package com.wangfei.helper.utils;

import java.util.HashMap;

/**
 * json返回结果的封装
 */
public class Result extends HashMap<String, Object> {

    /**
     * 初始化一个新创建的 AjaxResult 对象
     *
     * @param code 状态码
     * @param msg 返回内容
     * @param data 数据对象
     */
    public Result(int code, String msg, Object data)
    {
        super.put(CODE_TAG, code);
        super.put(MSG_TAG, msg);
        super.put(DATA_TAG, data);
    }

    public static final int CODE_SUCCESS = 200;

    public static final int CODE_ERROR = 500;

    public static final String CODE_TAG = "code";

    public static final String MSG_TAG = "msg";

    public static final String DATA_TAG = "data";

    public static Result success()
    {
        return new Result(CODE_SUCCESS, "操作成功", null);
    }

    public static Result success(Object data)
    {
        return new Result(CODE_SUCCESS, "success", data);
    }

    public static Result error()
    {
        return new Result(CODE_ERROR, "操作失败", null);
    }

    public static Result error(String msg)
    {
        return new Result(CODE_ERROR, msg, null);
    }
}
